/**
 * Created by tanglonghai on 17-1-6.
 */
$(document).ready(function() {
    Highcharts.setOptions({
        global: {
            useUTC: false
        },
        colors:['#F0382B','#28A1F6','#27D834']
    });
    c = 0;
    Connectstatus = 1;
    Connectseriesname = new Array();
    ConnectData = 0;
    $('#connect').click(function () {
        var splinename = $("#ConnectText").val();
        alert(splinename);
        alert(c);
        var params = {};
        if(Connectseriesname.length != 0){
            for(i = 0;i < Connectseriesname.length;i++){
                if(Connectseriesname[i] == splinename){
                    Connectstatus = 0;
                    break;
                }
            }
            if(Connectstatus == 1){
                Connectseriesname[c] = splinename;
                params.ipAddress = Connectseriesname[c];
                $.ajax({
                    type: "post",
                    url: "http://localhost:8080/analyReachable.action",
                    data:params,
                    dataType: "json",

                    success: function (res, status) {
                        ConnectData = parseFloat(res.reachable);
                        chart.addSeries({name:Connectseriesname[c],data:[ConnectData]});
                        c = c + 1;
                    },
                    error: function (res, status, xhr) {
                        alert(res);
                        alert(status);
                        alert(xhr);
                    }
                });
            }
            else{
                alert("该IP已经使用");
            }
        }
        else {
            Connectseriesname[c] = splinename;
            params.ipAddress = Connectseriesname[c];
            $.ajax({
                type: "post",
                url: "http://localhost:8080/analyReachable.action",
                data:params,
                dataType: "json",

                success: function (res, status) {
                    ConnectData = parseFloat(res.reachable);
                    chart.addSeries({name:Connectseriesname[c],data:[ConnectData]});
                    c = c + 1;
                },
                error: function (res, status, xhr) {
                    alert(res);
                    alert(status);
                    alert(xhr);
                }
            });
        }
    });
    var chart;
    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'connectrate',
            type: 'column'
        },
        title: {
            text: '<b>综合应用设计</b>'
        },
        subtitle: {
            text: '数据连通率总结柱状图'
        },
        xAxis: {
            categories: [
                'The rate of connection',
            ],
            crosshair: true
        },
        yAxis: {
            min: 0,
            title: {
                text: 'value'
            }
        },
        tooltip: {
            headerFormat: '<span style="font-size:15px"><b>{point.key}</b></span><table>',
            pointFormat: '<tr><td style="color:{series.color};padding:0"></b>{series.name}: </td>' +
            '<td style="padding:0"><b>{point.y:.1f}</b></td></tr>',
            useHTML: true
        },
        plotOptions: {
            column: {
                pointPadding: 0.2,
                borderWidth: 0
            }
        },
        credits: {
            enabled: false
        },
        series: []
    });
});
